package com.ydd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ydd.dto.LinkDTO;
import com.ydd.entity.Link;
import com.ydd.mapper.LinkMapper;
import com.ydd.service.ILinkService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hgz
 * @since 2023-05-30
 */
@Service
public class LinkServiceImpl extends ServiceImpl<LinkMapper, Link> implements ILinkService {

    @Autowired
    private LinkMapper linkMapper;
    @Override
    public List<Link> getPage(LinkDTO linkDTO) {

        LambdaQueryWrapper<Link> queryWrapper =
                new LambdaQueryWrapper<>();
        queryWrapper.like(linkDTO.getType()!=null,Link::getType,linkDTO.getType());

        List<Link> linkPage = linkMapper.selectList(queryWrapper);

        return linkPage;
    }

    @Override
    public Link rowInfo(Integer id) {

       Link link = linkMapper.selectById(id);
        return link;
    }

    @Override
    public void upd(Link link) {
        linkMapper.updateById(link);
    }

    @Override
    public void del(Integer id) {
        linkMapper.deleteById(id);
    }
    @Override
    public void add(Link link) {
        linkMapper.insert(link);
    }
}
